package edu.tgc.entity.log;

import java.util.Date;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import edu.tgc.entity.system.BaseEntity;

@Entity
public class LogEntry extends BaseEntity {

    private static final long serialVersionUID = -2703571409581911880L;

    @Transient
    public static LogEntry faild(String username, String ip, Date createTime, String message, String exception) {
        return new LogEntry(username, ip, false, createTime, message, exception);
    }

    @Transient
    public static LogEntry success(String username, String ip, Date createTime) {
        return new LogEntry(username, ip, true, createTime, null, null);
    }

    protected Date createTime;
    protected String exception;
    protected String ip;
    protected String message;

    protected Boolean success;

    protected String username;

    public LogEntry() {
        super();
    }

    public LogEntry(String username, String ip, Boolean success, Date createTime, String message, String exception) {
        this.username = username;
        this.ip = ip;
        this.success = success;
        this.createTime = createTime;
        this.message = message;
        this.exception = exception;
    }

    public LogEntry(UUID id) {
        super(id);
    }

    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreateTime() {
        return this.createTime;
    }

    @Column(length = 255)
    public String getException() {
        return this.exception;
    }

    @Column(length = 39)
    public String getIp() {
        return this.ip;
    }

    @Column(length = 127)
    public String getMessage() {
        return this.message;
    }

    public Boolean getSuccess() {
        return this.success;
    }

    @Column(length = 31)
    public String getUsername() {
        return this.username;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public void setException(String exception) {
        this.exception = exception;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public void setUsername(String username) {
        this.username = username;
    }

}
